#!/bin/bash
PROJECT_DIR='temp'
echo 'start'
rm -rf $PROJECT_DIR

echo 'clone code'$1
git clone $1 $PROJECT_DIR
cd $PROJECT_DIR
npm install

echo 'eslint check'
./node_modules/.bin/eslint ./

if [ $? -eq 1 ]; then
  PASS=false
fi
echo -e "\nJavascript validation completed!\n"
if ! $PASS; then
  echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
  exit 1
else
  echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
exit $?